package com.yc.sole.system.controller;

import com.yc.sole.framework.mybatis.page.BaseBatchIdsReq;
import com.yc.sole.framework.mybatis.page.BasePageReq;
import com.yc.sole.framework.mybatis.page.Paging;
import com.yc.sole.framework.result.Result;
import com.yc.sole.framework.validate.DeleteGroup;
import com.yc.sole.framework.validate.SaveGroup;
import com.yc.sole.framework.validate.UpdateGroup;
import com.yc.sole.framework.web.PreAuth;
import com.yc.sole.system.biz.BizLogBiz;
import com.yc.sole.system.request.BizLogQueryReq;
import com.yc.sole.system.request.BizLogReq;
import com.yc.sole.system.response.BizLogResp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yizuomin
 * @date 2024-03-20
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
public class BizLogController {

    private final BizLogBiz bizLogBiz;

    /**
     * 新增
     *
     * @param bizLogReq
     * @return RestResult
     */
    @PreAuth(value = "system:bizLog:save", description = "新增")
    @PostMapping("/api/system/bizLog/saveBizLog")
    public Result<Void> saveBizLog(@RequestBody @Validated(SaveGroup.class) BizLogReq bizLogReq) {
        bizLogBiz.saveBizLog(bizLogReq);
        return Result.success();
    }

    /**
     * 通过Id修改
     *
     * @param bizLogReq
     * @return RestResult
     */
    @PreAuth(value = "system:bizLog:update", description = "修改")
    @PostMapping("/api/system/bizLog/updateBizLogById")
    public Result<Void> updateBizLogById(@RequestBody @Validated(UpdateGroup.class) BizLogReq bizLogReq) {
        bizLogBiz.updateBizLogById(bizLogReq);
        return Result.success();
    }

    /**
     * 通过id批量删除
     *
     * @param baseBatchIdsReq
     * @return RestResult
     */
    @PreAuth(value = "system:bizLog:delete", description = "删除")
    @PostMapping("/api/system/bizLog/deleteBizLog")
    public Result<Void> deleteBizLog(@RequestBody @Validated(DeleteGroup.class) BaseBatchIdsReq baseBatchIdsReq) {
        bizLogBiz.deleteBizLogByIds(baseBatchIdsReq.getIds());
        return Result.success();
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return Result
     */
    @PreAuth(value = "system:bizLog:select", description = "查询")
    @PostMapping("/api/system/bizLog/selectBizLogById/{id}")
    public Result<BizLogResp> selectBizLogById(@PathVariable Long id) {
        return Result.data(bizLogBiz.selectBizLogById(id));
    }


    /**
     * 分页查询
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "system:bizLog:select", description = "查询", check = false)
    @PostMapping("/api/system/bizLog/selectBizLogPage")
    public Result<Paging<BizLogResp>> selectBizLogPage(@RequestBody @Validated BasePageReq<BizLogQueryReq> basePageReq) {
        return Result.data(bizLogBiz.selectBizLogPage(basePageReq.toPage(), basePageReq.getQuery()));
    }

    /**
     * 分页查询
     *
     * @param basePageReq
     * @return Result
     */
    @PreAuth(value = "system:bizLog:select", description = "查询", check = false)
    @PostMapping("/api/system/bizLog/selectBizLogByBizId")
    public Result<List<BizLogResp>> selectBizLogByBizId(@RequestBody @Validated BizLogQueryReq basePageReq) {
        return Result.data(bizLogBiz.selectBizLogByBizId(basePageReq));
    }
}
